package com.niuke;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 46. 排队游戏
 * https://blog.csdn.net/hihell/article/details/129019167
 */
public class NiukeMoni46buhui {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] input = scanner.nextLine().split(" ");
        int dpJi[] = new int[input.length]; // 奇数index为峰
        int dpOu[] = new int[input.length]; // 偶数index为峰

        int[] ji = new int[input.length];
        int[] ou = new int[input.length];

        for (int i = 0; i < input.length; i++) {
            int curr = Integer.parseInt(input[i]);
            ji[i] = curr;
            ou[i] = curr;
        }

        // 只得到偶数下标为峰的dp结果
        for (int i = 1; i < ou.length - 1; i++) {
            int curr = ou[i];
            int prev = ou[i - 1];
            int next = ou[i + 1];

            if (i % 2 == 0) {
                if (curr >= prev && curr >= next) {
                    dpOu[i] = dpOu[i - 1];
                } else {
                    if (curr < prev && curr < next) {
                        if (next >= prev) { // 把后面和中间交换
                            ou[i - 1] = prev;
                            ou[i] = next;
                            ou[i + 1] = curr;
                        } else { // 把前面和中间交换
                            ou[i - 1] = curr;
                            ou[i] = prev;
                            ou[i + 1] = next;
                        }
                    } else {
                        if (next >= prev) { // 把前面和中间交换
                            ou[i - 1] = curr;
                            ou[i] = prev;
                            ou[i + 1] = next;
                        } else { // 把后面和中间交换
                            ou[i - 1] = prev;
                            ou[i] = next;
                            ou[i + 1] = curr;
                        }
                    }
                    dpOu[i] = dpOu[i - 1] + 1;
                }
            } else {
                if (curr > prev) {
                    if (next >= prev) { // 把前面和中间交换
                        ou[i - 1] = curr;
                        ou[i] = prev;
                        ou[i + 1] = next;
                    } else { // 把后面和中间交换
                        ou[i - 1] = prev;
                        ou[i] = next;
                        ou[i + 1] = curr;
                    }
                    dpOu[i] = dpOu[i - 1] + 1;
                } else { // 不做调整
                    dpOu[i] = dpOu[i - 1];
                }
            }

        }

        // 只得到奇数下标为峰的dp结果
        for (int i = 1; i < ji.length - 1; i++) {
            int curr = ji[i];
            int prev = ji[i - 1];
            int next = ji[i + 1];

            if (i % 2 == 0) {
                if (curr > prev) {
                    if (next >= prev) { // 把前面和中间交换
                        ji[i - 1] = curr;
                        ji[i] = prev;
                        ji[i + 1] = next;
                    } else { // 把后面和中间交换
                        ji[i - 1] = prev;
                        ji[i] = next;
                        ji[i + 1] = curr;
                    }
                    dpJi[i] = dpJi[i - 1] + 1;
                } else {
                    dpJi[i] = dpJi[i - 1];
                }
            } else {
                if (curr >= prev && curr >= next) {
                    dpJi[i] = dpJi[i - 1];
                } else {
                    if (curr < prev && curr < next) {
                        if (next >= prev) { // 把前面和中间交换
                            ji[i - 1] = curr;
                            ji[i] = prev;
                            ji[i + 1] = next;
                        } else { // 把后面和中间交换
                            ji[i - 1] = prev;
                            ji[i] = next;
                            ji[i + 1] = curr;
                        }
                    } else {
                        if (next >= prev) { // 把后面和中间交换
                            ji[i - 1] = prev;
                            ji[i] = next;
                            ji[i + 1] = curr;
                        } else { // 把前面和中间交换
                            ji[i - 1] = curr;
                            ji[i] = prev;
                            ji[i + 1] = next;
                        }
                    }
                    dpJi[i] = dpJi[i - 1] + 1;
                }
            }
        }


        System.out.println("奇数下标为峰 = " + Arrays.toString(ji));
        System.out.println(dpJi[dpJi.length - 2]);
        System.out.println("偶数下标为峰 = " +Arrays.toString(ou));
        System.out.println(dpOu[dpOu.length - 2]);

    }

}
